//获取应用实例
const app = getApp()
let pageIndex = 1;
let enableLoadmore = false;

const pageSize = 20;
Component({
  data: {
    isUpper: false,
    isLower: false,
    list: [],
    triggered: true
  },

  properties: {
    status: {
      type: Number,
      value: 2
    },
    isHidden: {
      type: Boolean,
      value: true
    }
  },

  pageLifetimes: {
    show() {
      this.getDataList();
    },
  },

  refresh() {
    this.onLoad()
    this.setData({
      triggered: false
    })
  },

  methods: {
    getDataList() {
      let that = this;
      wx.showNavigationBarLoading();
      app.$http.getInterviewList(that.properties.status, pageIndex, pageSize).then(res => {
        this.data.isUpper = false;
        this.data.isLower = false;

        this.setData({
          triggered: false
        })

        wx.hideNavigationBarLoading({
          success: (res) => {},
        });

        if (pageIndex == 1) {
          that.data.list = res;
        } else {
          that.data.list = that.data.list.concat(res);
        }

        if (res.length < pageSize) {
          enableLoadmore = false;
        } else {
          enableLoadmore = true;
        }

        that.setData({
          "list": that.data.list,
        })
      });
    },

    itemClick: function (event){
      app.$routes.goTo(app.$routes.interview_detail,{id:event.currentTarget.id});
    },

    refresh() {
      pageIndex = 1;
      this.getDataList();
    },

    bindscrolltolower: function () {
      console.log("上拉加载");
      if (!enableLoadmore) {
        return;
      }

      console.log("上拉加载");
      if (this.data.isLower) {
        return
      }

      pageIndex++;

      this.getDataList();

    },

    // bindscrolltoupper: function () {
    //   if (this.data.isUpper) {
    //     return
    //   }
    //   console.log("下拉刷新");
    //   pageIndex = 1;

    //   this.data.isUpper = true;
    //   this.getDataList();


    // }
  }


})